home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / option.exe / TOPTVIEW.CPP < prev    next >
C/C++ Source or Header  |  1992-10-25  |  3KB  |  122 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       toptview.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TOptionViewer member functions            */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TKeys
  19. #define Uses_TOptionViewer
  20. #define Uses_TListViewer
  21. #define Uses_TScrollBar
  22. #define Uses_TEvent
  23. #define Uses_TCollection
  24. #include <tv.h>
  25. #include "TOption.h"
  26.  
  27. #if !defined( __CTYPE_H )
  28. #include <ctype.h>
  29. #endif  // __CTYPE_H
  30.  
  31. #if !defined( __STRING_H )
  32. #include <String.h>
  33. #endif  // __STRING_H
  34.  
  35. #if !defined( __DOS_H )
  36. #include <Dos.h>
  37. #endif  // __DOS_H
  38.  
  39. #define cpOptionViewer "\x06\x06\x07\x06\x06"
  40.  
  41. TOptionViewer::TOptionViewer( const TRect& bounds,
  42.                                 TScrollBar *aHScrollBar,
  43.                                 TScrollBar *aVScrollBar,
  44.                                 TCollection *aList ) :
  45.         TListViewer(bounds, 1, aHScrollBar, aVScrollBar),
  46.         items( aList )
  47.     {
  48.     setRange( (aList == 0) ? 0 : aList->getCount() );
  49.     if( range > 0 )
  50.         focusItem( 0 );
  51.     if( hScrollBar )
  52.         hScrollBar->setRange( 0, optionWidth() - size.x + 3 );
  53.     }
  54.  
  55. TPalette& TOptionViewer::getPalette() const
  56.     {
  57.     static TPalette palette( cpOptionViewer, sizeof( cpOptionViewer )-1 );
  58.     return palette;
  59.     }
  60.  
  61. void TOptionViewer::getText( char *dest, short item, short )
  62.     {
  63.     if (items != 0 )
  64.         strcpy( dest, (const char *)(items->at(item)) );
  65.     else
  66.         *dest = EOS;
  67.     }
  68.  
  69. void TOptionViewer::handleEvent( TEvent& event )
  70.     {
  71.     if( (event.what == evMouseDown && event.mouse.doubleClick) ||
  72.         (event.what == evKeyDown && event.keyDown.keyCode == kbEnter)
  73.       )
  74.         {
  75.         endModal( cmOK );
  76.         clearEvent( event );
  77.         }
  78.     else
  79.         if( (event.what ==  evKeyDown && event.keyDown.keyCode == kbEsc) ||
  80.             (event.what ==  evCommand && event.message.command ==  cmCancel)
  81.           )
  82.             {
  83.             endModal( cmCancel );
  84.             clearEvent( event );
  85.             }
  86.         else
  87.             TListViewer::handleEvent( event );
  88.     }
  89.  
  90. int TOptionViewer::optionWidth()
  91.     {
  92.     int width = 0;
  93.     if( items )
  94.         {
  95.         int count = items->getCount();
  96.         for( int i = 0; i < count; i++ )
  97.             {
  98.             int T = strlen( (char *)(items->at(i)) );
  99.             width = max( width, T );
  100.             }
  101.         }
  102.     return width;
  103.     }
  104.  
  105. TCollection *TOptionViewer::list()
  106.     {
  107.     return items;
  108.     }
  109.  
  110. void TOptionViewer::newList( TCollection *aList )
  111.     {
  112.     destroy( items );
  113.     items = aList;
  114.     if( aList != 0 )
  115.         setRange( aList->getCount() );
  116.     else
  117.         setRange(0);
  118.     if( range > 0 )
  119.         focusItem(0);
  120.     drawView();
  121.     }
  122.